package com.designed.pattern.behavioral.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yifei
 * @description 消息
 * @date 2024/1/11
 **/
public class Subject {
    List<Observer> list = new ArrayList<>();

    Integer state;

    public int getState() {
        return state;
    }
    public void setState(Integer state){
        this.state = state;
        notifyObservers();
    }

    private void notifyObservers() {
        for (Observer observer : list) {
            observer.update();
        }
    }

    public void binding(Observer observer){
        list.add(observer);
    }


}
